import flowablerequest from '@/utils/request'

const wf_MyStartInstanceApi = {
  processList: 'flow/processList',
  findProcessInstanList: '/flow/findProcessInstanList',
  viewCharDiagram: '/flow/viewCharDiagram',
  loadStartForm: '/flow/loadStartForm',
  viewProcessDiagram: '/flow/viewFlowChart',
  endBusinessList: '/flow/endBusinessList',
  saveStartFormData: '/flow/saveStartFormData',
  view: '/flow/view',
  del: '/flow/delete',
  dels: '/flow/batchDel',
  outProcess: 'flow/suspendOrActivateProcess',
  saveVariable: '/flow/saveVariable',
  claimTask: 'flow/claimTask',
  claimTaskBatch: 'flow/claimTaskBatch',
  cleanClaimTask: '/flow/cleanClaimTask'
}

/**
	 * 业务分配给了某一组人员时，需要该组人员进行抢占。抢到了就将该业务给谁处理，其他人不能处理。
	 *
	 * @param taskid 任务id
	 * @param userid
	 * @return
	 */
export function claimTask (taskid, userid) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.claimTask,
    method: 'post',
    params: { taskid, userid }
  })
}

/**
	 * 批量分配业务给了某一组人员时，需要该组人员进行抢占。抢到了就将该业务给谁处理，其他人不能处理。
	 *
	 * @param taskids 任务id
	 * @param userid
	 * @return
	 */
export function claimTaskBatch (taskids, userid) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.claimTaskBatch,
    method: 'post',
    data: taskids,
    params: { userid }
  })
}

/*
  保存流程变量
*/
export function saveVariable (processinstanceid, map) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.saveVariable,
    method: 'post',
    params: { processinstanceid },
    data: map
  })
}

/*
  流程实例挂起
*/
export function outProcess (parameter, body = {}) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.outProcess,
    method: 'post',
    params: parameter,
    data: body
  })
}

/*
  提交表单开始流程
*/
export function saveStartFormData (parameter, body) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.saveStartFormData,
    method: 'post',
    params: parameter,
    data: body
  })
}

/*
  获取已处理业务
*/
export function endBusinessList (parameter) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.endBusinessList,
    method: 'post',
    params: parameter
  })
}

/*
  查看已完成的任务调用
*/
export function viewProcessDiagram (parameter) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.viewProcessDiagram,
    method: 'post',
    params: parameter
  })
}

/*
    获取流程名称, 编号下拉框数据
*/
export function loadStartForm (parameter) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.loadStartForm,
    method: 'post',
    params: parameter
  })
}

/*
    获取流程名称, 编号下拉框数据
*/
export function processList (params, data) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.processList,
    method: 'post',
    params: params,
    data: data
  })
}
/**
 * 根据状态值显示申请列表
 * 1. 进行中
 * 2. 完结
 * @param {*} userid
 */
export function findProcessInstanList (parameter, data) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.findProcessInstanList,
    method: 'post',
    params: parameter,
    data: data
  })
}

/**
 * 查看、编辑我发起的申请
 * @param {*} id
 */
export function viewWf_MyStartInstance (id) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.view + '/' + id,
    method: 'post'
  })
}
/**
 * 查询我发起的申请列表
 * @param {*} parameter
 */
export function queryWf_MyStartInstanceList (parameter) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.list,
    method: 'post',
    data: parameter
  })
}

/**
 * 删除我发起的申请
 * @param {*} id
 */
export function delWf_MyStartInstance (id) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.del + '/' + id,
    method: 'post'
  })
}

/**
 * 清空当前的流程任务的处理人
 */
export function cleanClaimTask (taskid) {
  return flowablerequest({
    url: wf_MyStartInstanceApi.cleanClaimTask,
    method: 'post',
    params: { taskId: taskid }
  })
}
